import axios from 'axios'
import store from '@/store'
import router from '@/router'


// axios.create 方法：复制一个 axios
const request = axios.create({
    baseURL: 'http://122.51.249.55:5000/api',
})

// 请求拦截器
request.interceptors.request.use(config => {
    if (store.getters["user/token"]) {
        config.headers.Authorization = store.getters["user/token"]
    }
    return config
}, error => {
    return Promise.reject(error)
})

// 响应拦截器 

request.interceptors.response.use(response => {
    return response.data
}, error => {
    return Promise.reject(error)
})


// 前置守卫

export default request
